package edu.pku.sei.act.main.provider;

import java.util.ArrayList;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import edu.pku.sei.act.main.project.ArchiModelerProject;
import edu.pku.sei.act.model.common.ArchiModel;
import edu.pku.sei.act.model.mote.Mote;
import edu.pku.sei.act.model.mote.PackageI;

public class ArchiModelerContentProvider implements ITreeContentProvider{

	@Override
	public Object[] getChildren(Object parentElement) {
		if(parentElement instanceof ArchiModelerProject){
			ArchiModelerProject project = (ArchiModelerProject) parentElement;
			return project.getModels().toArray();
		}else if (parentElement instanceof ArchiModel) {
			ArchiModel model = (ArchiModel) parentElement;
			return getChildrenOfArchiModel(model);
		}else if (parentElement instanceof Mote){
			Mote mote = (Mote) parentElement;
			return getChildrenOfMote(mote);
		}else if (parentElement instanceof PackageI){
			PackageI packageI = (PackageI)parentElement;
			return getChildrenOfPackage(packageI);
		}
		
		return new Object[0];
	}

	private Object[] getChildrenOfPackage(PackageI packageI) {
		ArrayList<Object> children = new ArrayList<Object>();
		children.add(packageI.getMote());
		return children.toArray();
	}

	private Object[] getChildrenOfArchiModel(ArchiModel model) {

		ArrayList<Object> children = new ArrayList<Object>();
		children.addAll(model.getDiagrams());
		children.addAll(model.getRootElements());
		return children.toArray();

	}
	
	private Object[] getChildrenOfMote(Mote mote){
		ArrayList<Object> children = new ArrayList<Object>();
		children.add(mote.getData());
		children.add(mote.getRadio());
		children.add(mote.getTimer());
		children.add(mote.getSimplerDevice());
		return children.toArray();
	}

	@Override
	public Object getParent(Object element) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean hasChildren(Object element) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Object[] getElements(Object inputElement) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		// TODO Auto-generated method stub
		
	}

}
